/**
 * 颜色常量定义
 * 统一管理项目中使用的颜色值，支持主题切换
 */

// 获取当前主题模式
export const isDarkMode = () => {
  return document.documentElement.classList.contains('dark')
}

// 基础颜色配置
export const COLORS = {
  // 主色调
  primary: '#409eff',
  primaryLight: '#79bbff',
  primaryDark: '#337ecc',
  
  // 成功色
  success: '#67c23a',
  successLight: '#95d475',
  successDark: '#529b2e',
  
  // 警告色 - 使用指定的辅助颜色
  warning: '#c67915',
  warningLight: '#d4941f',
  warningDark: '#a86312',
  
  // 危险色 - 使用指定的辅助颜色
  danger: '#c35c5d',
  dangerLight: '#d07677',
  dangerDark: '#a64a4b',
  
  // 错误色 - 使用指定的辅助颜色
  error: '#7c191e',
  errorLight: '#9a2328',
  errorDark: '#5e1317',
  
  // 信息色
  info: '#909399',
  infoLight: '#a6a9ad',
  infoDark: '#73767a',
  
  // 文本颜色
  textPrimary: isDarkMode() ? '#ffffff' : '#303133',
  textRegular: isDarkMode() ? '#e5e5e5' : '#606266',
  textSecondary: isDarkMode() ? '#b3b3b3' : '#909399',
  textPlaceholder: isDarkMode() ? '#8c8c8c' : '#a8abb2',
  
  // 背景颜色
  bgPrimary: isDarkMode() ? '#242732' : '#f2f3f5',
  bgSecondary: isDarkMode() ? '#2c2f3b' : '#ffffff',
  bgTertiary: isDarkMode() ? '#363a4b' : '#f5f7fa',
  
  // 边框颜色
  borderColor: isDarkMode() ? '#4a4e5f' : '#dcdfe6',
  borderColorLight: isDarkMode() ? '#525670' : '#e4e7ed',
  borderColorLighter: isDarkMode() ? '#5a5e81' : '#ebeef5',
}

// 图表颜色配置
export const CHART_COLORS = {
  // 基础图表颜色
  primary: COLORS.primary,
  success: COLORS.success,
  warning: COLORS.warning,
  danger: COLORS.danger,
  info: COLORS.info,
  
  // 渐变色配置
  gradients: {
    primary: ['#409eff', '#79bbff'],
    success: ['#67c23a', '#95d475'],
    warning: ['#c67915', '#d4941f'],
    danger: ['#c35c5d', '#d07677'],
    error: ['#7c191e', '#9a2328'],
  },
  
  // 图表系列颜色
  series: [
    COLORS.primary,
    COLORS.success,
    COLORS.warning,
    COLORS.danger,
    COLORS.info,
    COLORS.error
  ],
  
  // 背景色
  background: isDarkMode() ? 'rgba(44, 47, 59, 0.8)' : 'rgba(255, 255, 255, 0.8)',
  
  // 网格线颜色
  gridLine: isDarkMode() ? '#4a4e5f' : '#e4e7ed',
  
  // 坐标轴颜色
  axisLine: isDarkMode() ? '#525670' : '#dcdfe6',
  
  // 文本颜色
  text: COLORS.textRegular,
  
  // 提示框背景
  tooltipBg: isDarkMode() ? '#2c2f3b' : '#ffffff',
}

// 状态颜色映射
export const STATUS_COLORS = {
  // 通用状态
  active: COLORS.success,
  inactive: COLORS.info,
  pending: COLORS.warning,
  approved: COLORS.success,
  rejected: COLORS.danger,
  error: COLORS.error,
  
  // 岗位状态
  draft: COLORS.info,
  published: COLORS.success,
  closed: COLORS.warning,
  expired: COLORS.danger,
  
  // 申请状态
  submitted: COLORS.primary,
  reviewing: COLORS.warning,
  accepted: COLORS.success,
  declined: COLORS.danger,
  
  // 面试状态
  scheduled: COLORS.primary,
  completed: COLORS.success,
  cancelled: COLORS.danger,
  rescheduled: COLORS.warning,
}

// 角色颜色映射
export const ROLE_COLORS = {
  admin: COLORS.danger,
  teacher: COLORS.warning,
  student: COLORS.primary,
  hr: COLORS.success,
  company: COLORS.info,
}

// 优先级颜色映射
export const PRIORITY_COLORS = {
  high: COLORS.danger,
  medium: COLORS.warning,
  low: COLORS.success,
  urgent: COLORS.error,
}

// 获取响应式颜色值
export const getResponsiveColor = (colorKey: keyof typeof COLORS) => {
  // 监听主题变化，返回对应的颜色值
  const updateColor = () => {
    const isDark = isDarkMode()
    
    switch (colorKey) {
      case 'textPrimary':
        return isDark ? '#ffffff' : '#303133'
      case 'textRegular':
        return isDark ? '#e5e5e5' : '#606266'
      case 'textSecondary':
        return isDark ? '#b3b3b3' : '#909399'
      case 'textPlaceholder':
        return isDark ? '#8c8c8c' : '#a8abb2'
      case 'bgPrimary':
        return isDark ? '#242732' : '#f2f3f5'
      case 'bgSecondary':
        return isDark ? '#2c2f3b' : '#ffffff'
      case 'bgTertiary':
        return isDark ? '#363a4b' : '#f5f7fa'
      case 'borderColor':
        return isDark ? '#4a4e5f' : '#dcdfe6'
      case 'borderColorLight':
        return isDark ? '#525670' : '#e4e7ed'
      case 'borderColorLighter':
        return isDark ? '#5a5e81' : '#ebeef5'
      default:
        return COLORS[colorKey]
    }
  }
  
  return updateColor()
}

// 获取图表主题配置
export const getChartTheme = () => {
  const isDark = isDarkMode()
  
  return {
    backgroundColor: isDark ? '#2c2f3b' : '#ffffff',
    textStyle: {
      color: isDark ? '#e5e5e5' : '#606266'
    },
    title: {
      textStyle: {
        color: isDark ? '#ffffff' : '#303133'
      }
    },
    legend: {
      textStyle: {
        color: isDark ? '#e5e5e5' : '#606266'
      }
    },
    grid: {
      borderColor: isDark ? '#4a4e5f' : '#e4e7ed'
    },
    categoryAxis: {
      axisLine: {
        lineStyle: {
          color: isDark ? '#525670' : '#dcdfe6'
        }
      },
      axisTick: {
        lineStyle: {
          color: isDark ? '#525670' : '#dcdfe6'
        }
      },
      axisLabel: {
        color: isDark ? '#b3b3b3' : '#909399'
      },
      splitLine: {
        lineStyle: {
          color: isDark ? '#4a4e5f' : '#e4e7ed'
        }
      }
    },
    valueAxis: {
      axisLine: {
        lineStyle: {
          color: isDark ? '#525670' : '#dcdfe6'
        }
      },
      axisTick: {
        lineStyle: {
          color: isDark ? '#525670' : '#dcdfe6'
        }
      },
      axisLabel: {
        color: isDark ? '#b3b3b3' : '#909399'
      },
      splitLine: {
        lineStyle: {
          color: isDark ? '#4a4e5f' : '#e4e7ed'
        }
      }
    },
    tooltip: {
      backgroundColor: isDark ? '#2c2f3b' : '#ffffff',
      borderColor: isDark ? '#4a4e5f' : '#dcdfe6',
      textStyle: {
        color: isDark ? '#e5e5e5' : '#606266'
      }
    }
  }
}

export default COLORS
